/**
 * JSparrow - Une version numérique du jeu "Attention Pirates !" - Copyright (C) 2014 Black Pearl
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <http://www.gnu.org/licenses/>.
 */
package App.Vue;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import App.Vue.JPanel_Principal;

public class Panneau_Regles extends JPanel_Principal {
	
	//Elements graphiques
	private JButton boutonRetour;
	
	public Panneau_Regles() {
		super();
		
		//Creation des boutons
		this.boutonRetour = new JButton("Retour");	
		
		//Layout
		this.setLayout(new GridBagLayout());
		
		//Ajout du bouton au panel
		
        JEditorPane jEditorPane = new JEditorPane();
        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(jEditorPane);
        HTMLEditorKit kit = new HTMLEditorKit();
        jEditorPane.setEditorKit(kit);
        StyleSheet styleSheet = kit.getStyleSheet();
        
        //Récupération du code css
        String cssString = "";
        try{
        	List<String> cssStringList = Files.readAllLines(FileSystems.getDefault().getPath("res/html/regles/index_files", "index.css"), Charset.defaultCharset());
            for(String s: cssStringList) {
            	cssString += s;
            }
        }
        catch(IOException e){
        	e.printStackTrace();
        }
        styleSheet.addRule(cssString);
        
        
        Document doc = kit.createDefaultDocument();
        jEditorPane.setDocument(doc);
        
        //Récupération du code html
        String htmlString = "";
        try{
        	List<String> htmlStringList = Files.readAllLines(FileSystems.getDefault().getPath("res/html/regles", "index.html"), Charset.defaultCharset());            
        	for(String s: htmlStringList) {
            	htmlString += s;
            }
        }
        catch(IOException e){
        	e.printStackTrace();
        }
        jEditorPane.setText(htmlString);
        
        //Ajout des items au panneau
        this.addItem(scrollPane, 0, 1, 1, 1, GridBagConstraints.NORTH);
		this.addItem(this.boutonRetour, 0, 2, 1, 1, GridBagConstraints.SOUTH);

	}
	
	private void addItem(JComponent c, int x, int y, int width, int height, int align) {
		GridBagConstraints gc = new GridBagConstraints();
		gc.gridx = x;
		gc.gridy = y;
		gc.gridwidth = width;
		gc.gridheight = height;
		gc.weightx = 0;
		gc.weighty = 0;
		gc.insets = new Insets(2, 2, 2, 2);
		gc.anchor = align;
		gc.fill = GridBagConstraints.NONE;
		this.add(c, gc);
	}
}
